<?php
class user{
    public $table="mdkeji_chatfree_user";
    public function __construct(){

    }
    public function __destruct(){

    }
    public function getUser($openid){
        $user=pdo_get($this->table,array('openid'=>$openid));
        return $user;
    }
    public function getAllUser(){
        $res=pdo_getall($this->table,array());
        return $res;
    }
    public function getAllMember(){
        $result=pdo_fetchall("select openid,nickName,avatarUrl,manager,phone,score,remark from ".tablename($this->table)." order by manager desc,timein asc ");
        return $result;
    }
    public function updateUser($data,$con=array()){
        $result=pdo_update($this->table,$data,$con);
        return $result;
    }
    public function getUserNickName($nickName,$pwd){
        $result=pdo_get($this->table,array('nickName'=>$nickName,'password'=>$pwd));
        return $result;
    }
    public function getUserNickLike($nickName){
        $result=pdo_fetchall("select openid,nickName,avatarUrl,manager,phone,score,remark from ".tablename($this->table)." where nickName like :nickName",array(':nickName'=> "%".$nickName."%"));
        return $result;
    }
    public function existNickName($nickName){
        $result=pdo_get($this->table,array('nickName'=>$nickName));
        return $result;
    }
    public function insertUser($data){
        $result=pdo_insert($this->table,$data);
        return $result;
    }
    public function getAllUserOnline($room_id){
        $user=pdo_getall($this->table,array('room_id'=>$room_id,'online'=>1),array('openid','nickName','avatarUrl','manager'));
        return $user;
    }
    public function plusUserScore($openid,$score){
        $res=pdo_query("update ".tablename($this->table)." set score=score+:score where openid=:openid",array(':score'=>$score,':openid'=>$openid));
        return $res;
    }
    public function minusUserScore($openid,$score){
        $res=pdo_query("update ".tablename($this->table)." set score=score-:score where openid=:openid",array(':score'=>$score,':openid'=>$openid));
        return $res;
    }






}